import { useCallback } from "react";


export type UseOpenFileProps = {
    accept?: string,
    callback?: (file: File) => void,
    errMessage?: (suffix: string) => string
}
const useOpenFile = ({
    accept = "",
    callback
}: UseOpenFileProps) => {
    const open = useCallback(() => {
        const input = document.createElement("input")
        input.type = "file";
        input.accept = "image/*"
        input.click();
        input.onchange = ({ target: { files } }: any) => {
            const file = files[0];
            input.accept = accept
            if (!!callback) callback(file);
        }
    }, [callback]);
    return open
}
export default useOpenFile